home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0188_Re: Getting an environment.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  1.4 KB  |  60 lines

  1.  
  2.  
  3. >The GetEnvironmentVariable function retrieves the value of the specified variable from the environment block
  4. >of the calling process. The value is in the form of a null-terminated string of characters.
  5.  
  6. >DWORD GetEnvironmentVariable(
  7.  
  8. >    LPCTSTR  lpName,        // address of environment variable name 
  9. >    LPTSTR  lpBuffer,        // address of buffer for variable value 
  10. >    DWORD  nSize         // size of buffer, in characters
  11. >   );        
  12. >Parameters
  13.  
  14. >lpName
  15.  
  16. >Points to a null-terminated string that specifies the environment variable. 
  17.  
  18. >lpBuffer
  19.  
  20. Here is a simple unit I cooked for delphi 32 bit. It will give you the whole
  21. environment in the form of a string list. then , you can access it as usual 
  22.  
  23. env:=tenvironment.create;
  24. a:=env.values['PATH];
  25. env.free;
  26. etc etc
  27.  
  28. look up the values property of tstrings for more info.
  29.  
  30. -------------------------- cut here
  31.  
  32. unit uenv;
  33.  
  34. Interface
  35.  
  36. uses windows,classes;
  37.  
  38. type tenvironment=class(tstringlist)
  39.                    constructor create;
  40.                   end;
  41.  
  42. implementation
  43.  
  44. constructor tenvironment.create;
  45.  var base,p:pchar;
  46.      a:string;
  47.  begin
  48.   inherited create;
  49.   base:=GetEnvironmentStrings; <--- for 16-bits, change to GetDosEnvironment.
  50.   if base=nil then exit;
  51.   p:=base;
  52.   while p^<>#0 do
  53.    begin
  54.     a:=p; <-- for 16-bit change this to a:=strpas(p);
  55.     add(a);
  56.     p:=p+length(a)+1;
  57.    end;
  58.   FreeEnvironmentStrings(base);
  59.  end;
  60.